#include <stdio.h>
#include <string.h>

#define MAX 1010

int main(int argc, char *argv[])
{
	int m, n, k, l, d;
	int x1, y1, x2, y2, x[MAX], y[MAX], w[MAX];
	int i, j, t;
	scanf("%d %d %d %d %d", &m, &n, &k, &l, &d);
	for (i=1; i<=m; i++) {
		y[i] = 0;
	}
	for (i=1; i<=n; i++) {
		x[i] = 0;
	}
	for (i=0; i<d; i++) {
		scanf("%d %d %d %d", &y1, &x1, &y2, &x2);
		if (x1 == x2) {
			if (y1 > y2) {
				t = y1; y1 = y2; y2 = t;
			}
			y[y1]++;
		} else if (y1 == y2) {
			if (x1 > x2) {
				t = x1; x1 = x2; x2 = t;
			}
			x[x1]++;
		}
	}

	for (i=0; i<=m; i++) {
		w[i] = i;
	}
	for (i=1; i<m; i++) {
		for (j=i+1; j<=m; j++) {
			if (y[i] < y[j]) {
				t = y[i]; y[i] = y[j]; y[j] = t;
				t = w[i]; w[i] = w[j]; w[j] = t;
			}
		}
	}
	for (i=1; i<k; i++) {
		for (j=i+1; j<=k; j++) {
			if (w[i] > w[j]) {
				t = w[i]; w[i] = w[j]; w[j] = t;
			}
		}
	}

	printf("%d", w[1]);
	for (i=2; i<=k; i++) {
		printf(" %d", w[i]);
	}
	printf("\n");

	for (i=0; i<=n; i++) {
		w[i] = i;
	}
	for (i=1; i<n; i++) {
		for (j=i+1; j<=n; j++) {
			if (x[i] < x[j]) {
				t = x[i]; x[i] = x[j]; x[j] = t;
				t = w[i]; w[i] = w[j]; w[j] = t;
			}
		}
	}
	for (i=1; i<l; i++) {
		for (j=i+1; j<=l; j++) {
			if (w[i] > w[j]) {
				t = w[i]; w[i] = w[j]; w[j] = t;
			}
		}
	}

	printf("%d", w[1]);
	for (i=2; i<=l; i++) {
		printf(" %d", w[i]);
	}
	printf("\n");


	return 0;
}
